package com.klic.horloge.util;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;

import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;

import com.klic.horloge.R;

import android.os.AsyncTask;
import android.util.Log;
import android.widget.TextView;

public class Weather extends AsyncTask<String, Void, String>{

	private String temperature = "";
	
	@Override
	protected String doInBackground(String... urls) {
		String response = "";
		
	      for (String url : urls) {
	        DefaultHttpClient client = new DefaultHttpClient();
	        HttpGet httpGet = new HttpGet(url);
	        try {
	          HttpResponse execute = client.execute(httpGet);
	          InputStream content = execute.getEntity().getContent();

	          BufferedReader buffer = new BufferedReader(new InputStreamReader(content));
	          String s = "";
	          while ((s = buffer.readLine()) != null) {
	        	Log.d("MyActivity",s);
	            response += s;
	          }

	        } catch (Exception e) {
	          e.printStackTrace();
	        }
	      }
	      return response;
	}
	
	private void extractTemperatureFromXML(String xml){
		this.temperature = xml.substring(xml.indexOf("temp", xml.indexOf("yweather:condition")),xml.indexOf("temp", xml.indexOf("yweather:condition"))+10);
	}

	public String getTemperature() {
		return temperature;
	}
	
	
	
}
